/************************************************************************************** */
// 模拟雷达
import { dateFormat } from '/@/utils/date';
function stopMock() {
  console.log('end send');
  clearInterval(interval);
  // console.log('historyAIS: ', JSON.stringify(historyAIS));
  // console.log('historyRadar: ', JSON.stringify(historyRadar));
}
/************************************************************************************** */
import AISList from './components/mock/AIS.json';
import radarList from './components/mock/oneleida.json';
import { getLonLatByXY, getSpeedByV } from './components/map/js/util.js';
let interval = null;
const readAISList = AISList;
const readRadarList = radarList;
// 虚拟AIS
let startTime = '2025-10-10 11:11:11';
startTime = +new Date(startTime);
let AISIds = {};
let historyAIS = {};
let radarIds = {};
let historyRadar = {};
function mockAIS() {
  console.log('start AIS');
  for (let key in readAISList) {
    AISIds[key] = 0;
    historyAIS[key] = [];
    if (startTime > +new Date(readAISList[key][0].dataTime)) {
      startTime = +new Date(readAISList[key][0].dataTime);
    }
  }
  console.log('startTime: ', dateFormat(startTime));
  for (let key in readRadarList) {
    radarIds[key] = 0;
    historyRadar[key] = [];
    if (startTime > +new Date(readRadarList[key][0].dataTime)) {
      startTime = +new Date(readRadarList[key][0].dataTime);
    }
  }
  console.log('startTime: ', dateFormat(startTime));
  interval = setInterval(() => {
    for (let key in readAISList) {
      const item = readAISList[key][AISIds[key]];
      if (item) {
        if (+new Date(item.dataTime) === startTime) {
          item.dataTime = dateFormat(new Date());
          ++AISIds[key];
          MqttJS.sendMessage(`/ais/point/${item.mmsi}`, item);
          historyAIS[key].push(item);
        }
      }
    }
    for (let key in readRadarList) {
      const item = readRadarList[key][radarIds[key]];
      if (item) {
        if (+new Date(item.dataTime) === startTime) {
          const { latitude, longitude } = getLonLatByXY(item.x, item.y, item.secret === '125' ? 'bei' : 'nan');
          const radarData = {
            targetSn: item.id,
            x: item.x,
            y: item.y,
            longitude,
            latitude,
            speed: getSpeedByV(item),
            // speed: 5,
            direction: 23,
            course: 23,
            distance: 0,
            rcs: 0,
            secret: item.secret,
            dataTime: dateFormat(new Date()),
          };
          ++radarIds[key];
          MqttJS.sendMessage(`/radar/point/${item.id}`, radarData);
          historyRadar[key].push(radarData);
        }
      }
    }
    startTime += 1000;
  }, 1000);
}
/************************************************************************************** */


/***************** 提取AIS和雷达数据 ******************** */
import * as mockJS from './js/mock/camera.js';
function tiquAIS() {
  console.log('111');
  const yuanshiData = mockJS.extractRadarAndClassBData();
  // const yuanshiData = mockJS.extractRadarBData();
  const AISList = mockJS.fenliAIS(yuanshiData.classBData);
  const RadarList = mockJS.fenliLeida(yuanshiData.radarData, 'realId');
  console.log('******************************');
  console.log('AISList: ', JSON.stringify(AISList));
  console.log('******************************');
  console.log('RadarList: ', JSON.stringify(RadarList));
  console.log('******************************');
}
// tiquAIS();
/********************** 计算摄像头角度 *************** */
mockJS.jisuanjiaoduNan();
/********************** 雷达去重时间 *************** */
import chongfuleida from './js/mock/AIS01081543/oneleida.json';
function deleteRadarByTime() {
  const list = mockJS.deleteRadarByTime(chongfuleida['126192']);
  console.log('去除后雷达: ', JSON.stringify(list));
}
// deleteRadarByTime();
/********************** 雷达计算间隔 *************** */
import leidashuju from './js/mock/AIS01081733/oneleida.json';
function leidatime() {
  const list = mockJS.leidatime(leidashuju);
  console.log('雷达间隔: ', JSON.stringify(list));
}
// leidatime();
/********************** 计算融合次数 *************** */
function jisuanrongheNumber() {
  const rongheNumber = mockJS.rongheNumber();
  console.log('******************************');
  console.log('rongheNumber: ', JSON.stringify(rongheNumber));
  console.log('******************************');
}
// jisuanrongheNumber();
/********************** 绘制轨迹 *************** */
import oneleida from './js/mock/AIS01061737/oneleida_all.json';
function huizhiguiji() {
  let index = 0;
  for (let key in { 12691: oneleida['12691'], 12662: oneleida['12662'] }) {
    // for (let key in oneleida) {
    if (oneleida[key].length >= 10) {
      ++index;
      const leidaType = oneleida[key][0].secret === '125' ? 'bei' : 'nan';
      const item = oneleida[key].map((m) => {
        const { latitude, longitude } = mockJS.getLonLatByXY(m.x, m.y, leidaType);
        m.latitude = latitude;
        m.longitude = longitude;
        return m;
      });
      const color = mockJS.getRandomColor();
      console.log('color: ', color);
      console.log('key: ', key);
      DrawJS.drawTravel(mapTarget, item, `tarvel_${key}`, color);
    }
  }
  console.log('index: ', index);
}
// setTimeout(() => {
//   huizhiguiji();
// }, 1.5 * 1000);
/*********************** 绘制AIS点 ************** */
import AISData from './js/mock/AIS01061737/AIS.json';
function huizhiAIS() {
  for (let key in AISData) {
    const color = mockJS.getRandomColor();
    DrawJS.drawPoint(mapTarget, AISData[key], {
      name: `AIS_${key}`,
      color,
    });
  }
}
// setTimeout(() => {
//   huizhiAIS();
// }, 1.5 * 1000);

/************************************* */